#!/bin/bash
#
set -e

WORK_DIR="$(dirname $0)/../"
cd $WORK_DIR

if [ -z $1 ]; then
    echo "请指定新仓库的地址，例如：bash init_new_project.sh ssh://git@git.innoviews.com:2022/insight/testx.git"
    exit 1
fi
read -p "
确认新仓库的地址：$1 [y|n] " choice
echo

if [ "$choice" != "y" ]; then
    echo "主动退出"
    exit 0
fi

if ! git remote -v |grep -q "insight/django-starter.git"; then
    echo "安全起见，禁止初始化非克隆自django-starter的项目，如果执行失败后需要再次执行初始化，请重新克隆django-starter后再执行该初始化脚本。"
    exit 1
fi

echo -e "\n开始初始化，请稍等..."
rm -rf .git
git init > /dev/null
git add . > /dev/null
git commit -m '从django-starter初始化项目' > /dev/null
git remote add origin $1
git push origin master > /dev/null

echo -e "\n初始化完成。"